#include "VSLight.h"
#include "VSGraphicInclude.h"
#include "VSSceneRender.h"
#include "VSStream.h"
using namespace VSEngine2;
IMPLEMENT_RTTI_NoCreateFun(VSLight,VSAVObject)
VSLight::VSLight()
{

	m_bEnable = true;
	m_Diffuse = VSColorRGBA(0.0f,0.0f,0.0f,0.0f);
	m_Specular = VSColorRGBA(0.0f,0.0f,0.0f,0.0f);
	
}
VSLight::~VSLight()
{

	
}
bool VSLight::IsRelative(VSSpatial * pSpatial)
{
	return true;
}
bool VSLight::Cullby(VSCuller & Culler)
{
	Culler.InsertLight(this);
	return true;
}
unsigned int VSLight::DiskUse()const
{
	unsigned int Use = VSAVObject::DiskUse();
	Use += sizeof(VSColorRGBA) * 2;
	Use += sizeof(bool);
	Use += sizeof(VSREAL) * 2;
	Use += sizeof(unsigned int) * 2;
	return Use;
}
bool VSLight::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!VSAVObject::Save(rStream,iSaveUse))
		return 0;


	if(!rStream.Write(&m_Diffuse,sizeof(VSColorRGBA)))
		return 0;
	iSaveUse += sizeof(VSColorRGBA);

	if(!rStream.Write(&m_Specular,sizeof(VSColorRGBA)))
		return 0;
	iSaveUse += sizeof(VSColorRGBA);

	if(!rStream.Write(&m_bIsCastShadow,sizeof(bool)))
		return 0;
	iSaveUse += sizeof(bool);

	if(!rStream.Write(&m_fZF,sizeof(VSREAL)))
		return 0;
	iSaveUse += sizeof(VSREAL);

	if(!rStream.Write(&m_fZN,sizeof(VSREAL)))
		return 0;
	iSaveUse += sizeof(VSREAL);

	if(!rStream.Write(&m_uiRTWidth,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	if(!rStream.Write(&m_uiRTHeight,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	return 1;
}
bool VSLight::Load(VSStream & rStream,unsigned int &iSaveUse)
{
	if(!VSAVObject::Load(rStream,iSaveUse))
		return 0;


	if(!rStream.Read(&m_Diffuse,sizeof(VSColorRGBA)))
		return 0;
	iSaveUse += sizeof(VSColorRGBA);

	if(!rStream.Read(&m_Specular,sizeof(VSColorRGBA)))
		return 0;
	iSaveUse += sizeof(VSColorRGBA);

	if(!rStream.Read(&m_bIsCastShadow,sizeof(bool)))
		return 0;
	iSaveUse += sizeof(bool);

	if(!rStream.Read(&m_fZF,sizeof(VSREAL)))
		return 0;
	iSaveUse += sizeof(VSREAL);

	if(!rStream.Read(&m_fZN,sizeof(VSREAL)))
		return 0;
	iSaveUse += sizeof(VSREAL);

	if(!rStream.Read(&m_uiRTWidth,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	if(!rStream.Read(&m_uiRTHeight,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	return 1;
}
bool VSLight::Clone(const VSObject *pObject,unsigned int uiType)
{
	const VSLight* Temp = DynamicCast<VSLight>(pObject); 
	if(!Temp)
		return 0;
	if(VSAVObject::Clone(pObject,uiType))
	{

		m_Diffuse	= Temp->m_Diffuse;
		m_Specular	= Temp->m_Specular;
		m_bIsCastShadow = Temp->m_bIsCastShadow;
		m_fZF = Temp->m_fZF;
		m_fZN = Temp->m_fZN;
		m_uiRTHeight = Temp->m_uiRTHeight;
		m_uiRTWidth = Temp->m_uiRTWidth;
		return 1;
	}
	else
	{
		return 0;

	}

}
void VSLight::SetCastShadow(bool bIsCastShadow)
{
	m_bIsCastShadow = bIsCastShadow;
}
void VSLight::DrawShadowMap()
{
	
}
